var e = require;
var t = module;
var i = exports;
Object.defineProperty(i, "__esModule", {value: !0}),
    (i.formatTimeString =
        i.time =
        i.timeEvent =
        i.getFullDisplayDateTime =
        i.getFullDisplayTime =
        i.getFullDisplayDate =
        i.addZero =
        i.isToday =
        i.isSameDay =
            void 0);
(t = e("typed-event")),
    (n.prototype.sync = function (e) {
        var t;
        if (null == e)
            return (
                (this.serverStartT = Date.now()),
                (this.clientStartT = Date.now()),
                (this.weekDay = -1),
                void (this.dayChangeT = -1)
            );
        (this.serverStartT = 1e3 * e.serverTime),
            (this.clientStartT = Date.now()),
            (this.weekDay = null !== (t = e.weekDay) && void 0 !== t ? t : -1),
            (this.dayChangeT = null !== (e = e.dayChangeT) && void 0 !== e ? e : -1);
    }),
    Object.defineProperty(n.prototype, "serverTime", {
        get: function () {
            return Math.floor((this.serverStartT + Date.now() - this.clientStartT) / 1e3);
        },
        enumerable: !1,
        configurable: !0
    }),
    Object.defineProperty(n.prototype, "timeZoneOffset", {
        get: function () {
            var e;
            return (
                null == this._cachedZoneOffset &&
                    ((e = new Date()), (e = Math.round(e.getTimezoneOffset() / 6)), (this._cachedZoneOffset = -e / 10)),
                this._cachedZoneOffset
            );
        },
        enumerable: !1,
        configurable: !0
    }),
    (n.prototype.startGlobalTimer = function (e) {
        var o = this;
        e.schedule(
            function (e) {
                var t = i.time.serverTime,
                    n = t > o.dayChangeT && 0 < o.dayChangeT;
                n && (o.dayChangeT += 86400), i.timeEvent.emit({now: t, dt: e, dayChange: n});
            },
            1,
            cc.macro.REPEAT_FOREVER
        );
    }),
    (e = n);
function n() {
    (this.DaySeconds = 86400),
        (this.weekDay = -1),
        (this._cachedZoneOffset = null),
        (this.dayChangeT = -1),
        (this.initd = !1);
}
function o(e, t) {
    (e = new Date(1e3 * e)), (t = new Date(1e3 * t));
    return e.getFullYear() == t.getFullYear() && e.getMonth() == t.getMonth() && e.getDate() == t.getDate();
}
function r(e) {
    return e < 10 ? "0" + e : e + "";
}
function a(e) {
    e = new Date(1e3 * e);
    return e.getFullYear() + "/" + r(e.getMonth() + 1) + "/" + r(e.getDate());
}
function s(e) {
    e = new Date(1e3 * e);
    return r(e.getHours()) + ":" + r(e.getMinutes()) + ":" + r(e.getSeconds());
}
(i.isSameDay = o),
    (i.isToday = function (e) {
        return o(i.time.serverTime, e);
    }),
    (i.addZero = r),
    (i.getFullDisplayDate = a),
    (i.getFullDisplayTime = s),
    (i.getFullDisplayDateTime = function (e) {
        return a(e) + " " + s(e);
    }),
    (i.timeEvent = new t.TypedEvent()),
    (i.time = new e()),
    (i.formatTimeString = function (e, t) {
        if (e <= 0) return t ? "00:00:00" : "00:00";
        var n = e % 60,
            o = (e = (e - n) / 60) % 60,
            i = (e - o) / 60,
            e = "";
        return (
            (0 < i || t) && (e += (i = i < 10 ? "0" + i : i) + ":"),
            (e += (o = o < 10 ? "0" + o : o) + ":") + (n = n < 10 ? "0" + n : n)
        );
    });
